package com.rs.utils;

import org.springframework.util.StringUtils;

import javax.xml.bind.JAXB;
import java.io.StringWriter;

public class XMLParserUtil {

    public static String marshal(Object root) {
        StringWriter writer = new StringWriter();
        JAXB.marshal(root, writer);
        return writer.toString();
    }

    public static String getXmlStr(String key, String value) {
        if (StringUtils.hasText(value)) {
            return "<" + key + ">" + value + "</" + key + ">";
        } else {
            return "<" + key + "></" + key + ">";
        }
    }
}
